import request from '@/utils/request'

// 获取商品列表
export const getProducts = async (data: any) => {
  return request
    .get('/products', {
      params: {
        ...data,
      },
    })
    .then((res: any) => {
      return res
    })
}

// 添加商品
export const addProduct = async (data: any) => {
  console.log(data)
  return request.post('/products/', data).then((res: any) => {
    return res
  })
}

// 批量添加商品
export const addProductList = async (data: any) => {
  console.log(data)
  return request.post('/products/upload/csv', data).then((res: any) => {
    return res
  })
}

// 删除商品
export const deleteProductById = async (id: any) => {
  return request.delete(`/products/${id}`).then((res: any) => {
    return res
  })
}
// 批量删除商品
export const deleteProductByIdList = async (data: any) => {
  console.log(data)
  return request
    .delete('/products/dl', {
      data,
    })
    .then((res: any) => {
      return res
    })
}
// 获取单个商品
export const getProductById = async (id: any) => {
  return request.get(`/products/${id}`).then((res: any) => {
    return res
  })
}

// 编辑商品
export const editProduct = async (id: any, data: any) => {
  return request.put(`/products/${id}`, data).then((res: any) => {
    return res
  })
}

// 编辑商品 SKU 信息
export const editProductSku = async (id: any, data: any) => {
  return request.put(`/products/variant/${id}`, data).then((res: any) => {
    return res
  })
}
